package com.ev.apis.controller.hr;

import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.utils.R;
import com.ev.hr.service.GenerateExcelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javassist.CannotCompileException;
import javassist.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 文件名称： com.ev.hr.GenerateExcelApiController.java</br>
 * 初始作者： ev-monitor</br>
 * 创建日期： 2020-05-08 13:03:33</br>
 * 功能说明： 动态模板下载 <br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者        日期       修改内容<br/>
 * ================================================<br/>
 * Copyright (c) 2020-2021 .All rights reserved.<br/>
 */
@Api(value = "/", tags = "动态模板下载")
@RestController
public class GenerateExcelApiController {
    @Autowired
    private GenerateExcelService generateExcelService;

    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/downLoadSalaryArchives", method = RequestMethod.GET, apiTitle = "下载薪资档案模板")
    @ApiOperation("下载薪资档案模板")
    public void downLoadSalaryArchives(
            @ApiParam(value = "是否需要携带数据") @RequestParam(value = "isShowData", defaultValue = "1", required = false) Integer isShowData,
            HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        boolean isData = isShowData == 1;
        generateExcelService.downLoadSalaryArchives(request,response,modelMap,isData);
    }

    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/importSalaryArchives", method = RequestMethod.POST, apiTitle = "导入薪资档案模板")
    @ApiOperation("导入薪资档案模板")
    @Transactional(rollbackFor = Exception.class)
    public R importSalaryArchives(@ApiParam(value = "文件信息", required = true) @RequestParam("file") MultipartFile file) throws IOException, CannotCompileException, NotFoundException {
        return generateExcelService.importSalaryArchives(file);
    }

    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/downLoadTax", method = RequestMethod.GET, apiTitle = "下载个税模板")
    @ApiOperation("下载个税模板")
    public void downLoadTax(
            @ApiParam(value = "是否需要携带数据") @RequestParam(value = "isShowData", defaultValue = "1", required = false) Integer isShowData,
            @ApiParam(value = "所属日期") @RequestParam(value = "monthDate", defaultValue = "", required = false) String monthDate,
            HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        boolean isData = isShowData == 1;
        generateExcelService.downLoadTax(request,response,modelMap,isData,monthDate);
    }

    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/importTax", method = RequestMethod.POST, apiTitle = "下载个税模板")
    @ApiOperation("导入个税模板")
    @Transactional(rollbackFor = Exception.class)
    public R importTax(@ApiParam(value = "文件信息", required = true) @RequestParam("file") MultipartFile file,
                       @ApiParam(value = "所属日期") @RequestParam(value = "monthDate", defaultValue = "", required = false) String monthDate
                       ) throws IOException, CannotCompileException, NotFoundException {
        return generateExcelService.importTax(file,monthDate);
    }

    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/downLoadSocialSecurity", method = RequestMethod.GET, apiTitle = "下载社保模板")
    @ApiOperation("下载社保模板")
    public void downLoadSocialSecurity(
            @ApiParam(value = "是否需要携带数据") @RequestParam(value = "isShowData", defaultValue = "1", required = false) Integer isShowData,
            @ApiParam(value = "所属日期") @RequestParam(value = "monthDate", defaultValue = "", required = false) String monthDate,
            HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        boolean isData = isShowData == 1;
        generateExcelService.downLoadSocialSecurity(request,response,modelMap,isData,monthDate);
    }

    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/importSocialSecurity", method = RequestMethod.POST, apiTitle = "导入社保模板")
    @ApiOperation("导入社保模板")
    @Transactional(rollbackFor = Exception.class)
    public R importSocialSecurity(@ApiParam(value = "文件信息", required = true) @RequestParam("file") MultipartFile file,
                                  @ApiParam(value = "所属日期") @RequestParam(value = "monthDate", defaultValue = "", required = false) String monthDate
                                  ) throws IOException, CannotCompileException, NotFoundException {
        return generateExcelService.importSocialSecurity(file,monthDate);
    }


    @ResponseBody
    @EvApiByToken(value = "/apis/exportExcel/downLoadRecord", method = RequestMethod.GET, apiTitle = "下载个税模板")
    @ApiOperation("导出薪资记录")
    public void downLoadRecord(
            @ApiParam(value = "是否需要携带数据") @RequestParam(value = "isShowData", defaultValue = "1", required = false) Integer isShowData,
            @ApiParam(value = "所属日期") @RequestParam(value = "monthDate", defaultValue = "", required = false) String monthDate,
            HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
        boolean isData = isShowData == 1;
        generateExcelService.downLoadRecord(request,response,modelMap,isData,monthDate);
    }

}
